package com.dongdongshop.controller;

import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.MyCollection;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.impl.CommentService;
import com.dongdongshop.util.PageBean;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @ClassName MongoDbController
 * @Author RC
 * @date 2021.01.04 23:14
 */
@Controller
@RequestMapping("comment")
public class MongoDbController {

    @Resource
    private CommentService commentService;

    private static final Logger logger = LoggerFactory.getLogger(MongoDbController.class);

    @RequestMapping("getComment")
    @ResponseBody
    public DataResult getComment(String goodsid,String commentlevel, @RequestParam(defaultValue = "1")Integer pageNumber, @RequestParam(defaultValue = "2")Integer pageSize){
        try {
            PageBean<MyCollection> myCollectionList = commentService.getComment(goodsid,commentlevel,pageNumber,pageSize);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(myCollectionList);
        }catch (Exception e){
            logger.error("有错误",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    @RequestMapping("saveComment")
    @ResponseBody
    public DataResult saveComment(MyCollection myCollection){
        try {
            //获取用户主体 判断是否登录
            TbUser user =(TbUser) SecurityUtils.getSubject().getPrincipal();
            myCollection.setNickname(user.getUsername());
            commentService.saveComment(myCollection);
            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.error("有错误",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }

   /* @RequestMapping("ReplyToComments")
    @ResponseBody
    public DataResult ReplyToComments(){
        try {
            List<MyCollection> myCollectionList = commentService.ReplyToComments();
            return DataResult.response(ResponseStausEnum.SUSSCESS);
        }catch (Exception e){
            logger.error("有错误",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }*/


}
